<!-- include tpl=header js="js/jquery.zoombie.js" -->
<section class="bg-light p-5 bg-default"{if $cate_rs.banner || $page_rs.banner} style="background:url('{$cate_rs.banner ? $cate_rs.banner.filename : $page_rs.banner.filename}') center center no-repeat;"{/if}>
	<h1 class="p-4 text-center">{$rs.title}</h1>
	<!-- if $rs.subtitle -->
	<h6 class="text-center">{$rs.subtitle}</h6>
	<!-- /if -->
	<div class="container">
		<div class="text-center d-block m-4">
			<small class="p-2 bg-light-50 rounded-lg ">
				发布日期：{func time_format $rs.dateline} &nbsp; &nbsp;
				浏览次数：{$rs.hits}
			</small>
		</div>
		<!-- if $rs.tag -->
		<div class="text-center m-3">
			<small class="p-2 bg-light-50 rounded-lg">
			标签：
			<!-- loop from=$rs.tag key=$k value=$v id=$idxx -->
			{$v.html}<!-- if $idxx.total != $idxx.num -->，<!-- /if -->
			<!-- /loop -->
			</small>
		</div>
		<!-- /if -->
	</div>
</section>

<!-- loop from=$rs.attrs key=$key value=$value id=$tmpid -->
<input type="hidden" data-id="{$key}" data-price="{$value.price}" data-stock="{$value.qty}" />
<!-- /loop -->
<script type="text/javascript">
function attr_select(id,aid)
{
	$("#attr_"+aid).val(id);
	$("div[name=attr"+aid+"]").each(function(i){
		var tid = $(this).attr('data');
		if(tid == id){
			$(this).addClass("selected");
		}else{
			$(this).removeClass('selected');
		}
	});
	remote_data(id,aid);
}
function attr_unselect(id,aid)
{
	$("#attr_"+aid).val('');
	$("div[name=attr"+aid+"][data="+id+"]").removeClass('selected');
	remote_data(id,aid);
}
function remote_data(id,aid)
{
	var qty = $("#buycount").val();
	if(!qty || qty<1){
		qty = 1;
	}
	var url = api_url('content','price','id={$rs.id}&qty='+qty+"&symbol=1");
	var ids = new Array();
	$("input[name=attr]").each(function(i){
		var val = $(this).val();
		if(val != ''){
			ids.push(val);
		}
	});
	if(ids && ids.length>0){
		url += "&attr="+ids.join(",");
	}
	$("select[data-name=apps]").each(function(i){
		var tname = $(this).attr("data-id");
		var val = $(this).val();
		url += "&"+tname+"_id="+val;
	});
	$.phpok.json(url,function(rs){
		if(!rs.status){
			$.dialog.tips(rs.info);
			if(id && aid && id != 'undefined' && aid != 'undefined'){
				attr_unselect(id,aid);
			}
			return false;
		}
		if(rs.status == 2){
			return true;
		}
		$("#showprice").html(rs.info.price_format);
		$("#stock_qty").html(rs.info.qty);
	});
}
function update_apps(name)
{
	remote_data();
}
$(document).ready(function(){
	$("#minus").click(function(){
		var o = $("#buycount").val();
		if(o<2){
			$.dialog.alert('要购买的数量不能少于1');
			return false;
		}
		o = parseInt(o) - 1;
		$("#buycount").val(o);
		remote_data();
	});
	$("#plus").click(function(){
		var o = $("#buycount").val();
		o = parseInt(o) + 1;
		$("#buycount").val(o);
		remote_data();
	});
	$("#buycount").blur(function(){
		remote_data();
	}).on("keyup",function(){
		remote_data();
	});
});
</script>
<section class="container p-0">
	<div id="slider_{$page_rs.id}" class="carousel slide" data-ride="carousel">
		<ol class="carousel-indicators">
			<!-- if !$rs.pictures && $rs.thumb -->
			<li data-target="#slider_{$page_rs.id}" data-slide-to="0" class="active"></li>
			<!-- /if -->
			<!-- loop from=$rs.pictures key=$key value=$value id=$tmpid -->
			<li data-target="#slider_{$page_rs.id}" data-slide-to="{$tmpid.index}"{if !$tmpid.index} class="active"{/if}></li>
			<!-- /loop -->
		</ol>
		<div class="carousel-inner">
			<!-- if !$rs.pictures && $rs.thumb -->
			<div class="carousel-item active">
				<img src="{$rs.thumb.gd.auto}" class="d-block w-100" alt="{$rs.title}" />
			</div>
			<!-- /if -->
			<!-- loop from=$rs.pictures key=$key value=$value id=$tmpid -->
			<div class="carousel-item{if !$tmpid.index} active{/if}">
				<img src="{$value.gd.auto}" class="d-block w-100" alt="{$rs.title} - {$tmpid.num}" />
			</div>
			<!-- /loop -->
		</div>
		<a class="carousel-control-prev" href="#slider_{$page_rs.id}" role="button" data-slide="prev">
			<span class="carousel-control-prev-icon" aria-hidden="true"></span>
			<span class="sr-only">下一张</span>
		</a>
		<a class="carousel-control-next" href="#slider_{$page_rs.id}" role="button" data-slide="next">
			<span class="carousel-control-next-icon" aria-hidden="true"></span>
			<span class="sr-only">下一张</span>
		</a>
	</div>
	<ul class="list-group list-group-flush">
		<!-- loop from=$rs.apps key=$key value=$value id=$tmpid -->
		<!-- if $value.me -->
		<li class="list-group-item">
			<div class="row">
				<div class="col-sm-4">
					{$value.me.title}
				</div>
				<div class="col">
					<select name="{$key}_id" id="{$key}_id" data-name="apps" data-id="{$key}">
						<!-- loop from=$value.list key=$k value=$v id=$idxx -->
						<option value="{$v.id}"{if $value.rs.id == $v.id} selected{/if}>{$v.title}</option>
						<!-- /loop -->
					</select>
				</div>
			</div>
		</li>
		<!-- /if -->
		<!-- /loop -->
		<!-- loop from=$rs.attrlist key=$key value=$value -->
		<li class="list-group-item">
			<div class="row">
				<div class="col-sm-4"><b>{$value.title}</b></div>
				<div class="col">
					<input type="hidden" name="attr" id="attr_{$value.id}" value="" />
					<div class="row row-cols-sm-1">
						<!-- loop from=$value.rslist key=$k value=$v id=$tmpid -->
						<div class="col">
							<div class="attr m-1" name="attr{$value.id}" data="{$v.id}" style="user-select: none;" onclick="attr_select('{$v.id}','{$value.id}')">
								<!-- if $v.pic --><img src="{$v.pic}" style="width:40px;height:40px" /><!-- /if -->
								{$v.title}
							</div>
						</div>
						<!-- /loop -->
					</div>
				</div>
			</div>
		</li>
		<!-- /loop -->
		<!-- if $rs.qty -->
		<li class="list-group-item">
			<div class="row">
				<div class="col-sm-4"><b>库存</b></div>
				<div class="col" id="stock_qty">{$rs.qty}</div>
			</div>
		</li>
		<!-- /if -->
		<li class="list-group-item">
			<div class="row">
				<div class="col-sm-4"><b>购买数量</b></div>
				<div class="col">
					<input name="buycount" id="buycount" value="1" type="number" min="1" onkeyup="value=value.replace(/[^\d]/g,'')" onblur="value=value.replace(/[^\d]/g,'')" />
				</div>
			</div>
		</li>
		<li class="list-group-item">
			<div class="row">
				<div class="col-sm-4"><b>价格</b></div>
				<div class="col">
					<!-- if $rs.min-max -->
					<span class="price" style="color:red;font-size:16px;" id="showprice">
						<!-- loop from=$rs.min-max key=$key value=$value id=$tmpid -->
						<!-- if $tmpid.index --> - <!-- /if -->
						{func price_format $value $rs.currency_id $config.currency_id}
						<!-- /loop -->
					</span>
					<!-- else -->
					<span class="price" style="color:red;font-size:16px;" id="showprice">{func price_format $rs.price $rs.currency_id $config.currency_id}</span>
					<!-- /if -->
				</div>
			</div>
			<!-- if $rs.wholesale -->
			<div class="row" style="margin-top:20px;">
				<div class="col">
					<table class="table table-bordered">
					<thead>
						<tr>
							<th>数量</th>
							<th>价格</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td scope="row">≥1</td>
							<td>{func price_format $rs.price $rs.currency_id}</td>
						</tr>
						<!-- loop from=$rs.wholesale key=$key value=$value id=$tmpid -->
						<tr>
							<td scope="row">≥{$value.qty}</td>
							<td>{func price_format $value.price $rs.currency_id}</td>
						</tr>
						<!-- /loop -->
					</tbody>
					</table>
				</div>
			</div>
			<!-- /if -->
		</li>
	</ul>
	<div class="row p-2">
		<div class="col">
			<button type="button" class="btn btn-primary" onclick="$.cart.add('{$rs.id}',$('#buycount').val())">
				<i class="fa fa-cart-plus"></i> 加入购物车
			</button>
		</div>
		<div class="col">
			<button type="button" class="btn btn-warning float-right" onclick="$.cart.onebuy('{$rs.id}',$('#buycount').val())">
				<i class="fa fa-check"></i> 立即购买
			</button>
		</div>
	</div>
	<div class="card mt-3 border-left-0 border-right-0 rounded-0">
		<div class="card-header">
			<ul class="nav nav-tabs card-header-tabs" role="tablist">
				<li><a href="#product-content" class="nav-link active" role="tab" data-toggle="tab">产品介绍</a></li>
				<!-- if $rs.params -->
				<li><a href="#product-params" class="nav-link" role="tab" data-toggle="tab">规格参数</a></li>
				<!-- /if -->
				<!-- if $rs.package && $rs.package.content -->
				<li><a href="#product-package" class="nav-link" role="tab" data-toggle="tab">包装清单</a></li>
				<!-- /if -->
				<li><a href="#product-service" class="nav-link" role="tab" data-toggle="tab">售后信息</a></li>
			</ul>
		</div>
		
		<div class="card-body p-0">
			<div class="tab-content">
				<div role="tabpanel" class="tab-pane active" id="product-content">
					<!-- loop from=$rs.contentpics key=$key value=$value id=$tmpid -->
					<div align="center"><img src="{$value.filename}" style="max-width:100%" /></div>
					<!-- /loop -->
					{$rs.content}
				</div>
				<!-- if $rs.params -->
				<div role="tabpanel" class="tab-pane pt-2" id="product-params">
					<!-- loop from=$rs.params key=$key value=$value id=$tmpid -->
					<h4>{$value.name}</h4>
					<hr />
					<!-- if $value.info && $value.info.title && $value.info.content -->
					<div class="row">
					<!-- loop from=$value.info.content key=$k value=$v id=$idx -->
						<!-- loop from=$value.info.title key=$kk value=$vv id=$idxx -->
						<div class="col{if $kk==0}-3{elseif $kk == 1}-5{else}-4 text-muted{/if} mt-2">{if $kk == 2 && $v[$kk]}备注：{/if}{$v[$kk]}</div>
						<!-- /loop -->
					<!-- /loop -->
					</div>
					<!-- /if -->
					<!-- if $value.note -->
					<div class="content">{$value.note}</div>
					<!-- /if -->
					<!-- if $tmpid.num != $tmpid.total --><hr /><!-- /if -->
					<!-- /loop -->
				</div>
				<!-- /if -->
				<!-- if $rs.package && $rs.package.content -->
				<div role="tabpanel" class="tab-pane" id="product-package">
					<table class="table">
						<thead class="thead-light">
							<tr>
								<!-- loop from=$rs.package.title key=$key value=$value id=$tmpid -->
								<th scope="col">{$value}</th>
								<!-- /loop -->
							</tr>
						</thead>
						<tbody>
							<!-- loop from=$rs.package.content key=$key value=$value id=$tmpid -->
							<tr>
								<th>{$value[0]}</th>
								<td>{$value[1]}</td>
							</tr>
							<!-- /loop -->
						</tbody>
					</table>
				</div>
				<!-- /if -->
				<div role="tabpanel" class="tab-pane" id="product-service">
					<!-- php:$t = phpok('after-sale-protection') -->
					{$t.content}
				</div>
				
			</div>
			
		</div>
	</div>
	<!-- if $page_rs.comment_status -->
	<div class="mt-2">
		<!-- include tpl=block/comment tid=$rs.id -->
	</div>
	<!-- /if -->
</section>
<!-- include tpl=footer -->
